# -*- coding: UTF-8 -*-
#encoding=utf-8

import sys
import ssl
import requests
import unicodedata
from dolphin.common.commonlogger import commonlogger
import numpy as numpy
from dolphin.config.confighelper import confighelper
from dolphin.common.utils import utils
from dolphin.common.dolphinhttpclient import dolphinhttpclient

ssl._create_default_https_context = ssl._create_unverified_context

type = sys.getfilesystemencoding()

from dolphin.common.commonlogger import commonlogger

#from Scrapy.cmdline import execute
logger = commonlogger().getlogger()

class SpiderUrlsRest:
    def __init__(self):
        return

    def get_query_url_by_restservice(self,spider_name):
        main_url = confighelper.getGlobalValue(self, 'rest_service_address') 
        param = "/spider/api/v1/spiderurls?spider_name=" + spider_name
        full_url = main_url + param
        query_result = dolphinhttpclient.get_response_data(dolphinhttpclient,full_url)
        response = query_result["data"]
        return response

    def put_query_url_by_restservice(self,data):
        response = {}
        try:
            url = confighelper.getGlobalValue(self, 'rest_service_address') + "/spider/api/v1/spiderurls"
            query_result = dolphinhttpclient.put(dolphinhttpclient,url,data)
            response = query_result["data"]
        except Exception as e:
            logger.error(e)
        return response